local gongqi = fk.CreateSkill {
  name = "ls__gongqi",
  tags = {"switch","Turn"},
}

Fk:loadTranslationTable{
  ["ls__gongqi"] = "弓骑",
  [":ls__gongqi"] = "转换技，回合技，你可将一张①基本②锦囊③装备牌当无距离限制的【杀】使用，你可不转换/转换两次，令此【杀】不计入次数/不可响应。",
  ["ls__gongqi1"] = "不转换",
  ["ls__gongqi2"] = "转换两次",

  ["$ls__gongqi1"] = "溃敌如去疾，对症下药！",
  ["$ls__gongqi2"] = "弯弓善射，千钧一击。",
}

local DIY = require "packages/diy_utility/diy_utility"

gongqi:addEffect("viewas", {
  pattern = "slash",
  card_filter = function(self, player, to_select, selected)
    local n = DIY.getSwitchState(player, gongqi.name)
    if n == 1 then
      return Fk:getCardById(to_select).type == Card.TypeBasic
    elseif n == 2 then
      return Fk:getCardById(to_select).type == Card.TypeTrick
    elseif n == 3 then
      return Fk:getCardById(to_select).type == Card.TypeEquip
    end
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("lvshi__slash")
    card:addSubcards(cards)
    card.skillName = gongqi.name
    return card
  end,
  before_use = function (self, player, use)
    local choices = {"ls__gongqi1", "ls__gongqi2", "Cancel"}
    local choice = player.room:askToChoice(player, {choices = choices, skill_name = gongqi.name})
    if choice == "ls__gongqi1" then
      use.extra_data = use.extra_data or {}
      use.extra_data_noswitch = true
      if not use.extraUse then
        player:addCardUseHistory(use.card.trueName, -1)
      end
    elseif choice == "ls__gongqi2" then
      use.extra_data = use.extra_data or {}
      use.extra_data_doubleswitch = true
      use.disresponsiveList = player.room.alive_players
    end
  end,
  after_use = function (self, player, use)
    if use.extra_data and use.extra_data_noswitch then
    else
      DIY.changeSwitchState(player, gongqi.name)
      if use.extra_data and use.extra_data_doubleswitch then
        DIY.changeSwitchState(player, gongqi.name)
      end
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(gongqi.name) == 0
  end,
  enabled_at_response = function (self, player, response)
    return not response and player:usedSkillTimes(gongqi.name) == 0
  end
})

gongqi:addEffect("targetmod", {
  bypass_distances = function (self, player, skill, card)
    return player:hasSkill(gongqi.name) and card and card.skillName == gongqi.name
  end
})

gongqi:addAcquireEffect(function (self, player, is_start)
  DIY.setSwitchState(player, gongqi.name, 1, 3)
end)

gongqi:addLoseEffect(function (self, player)
  DIY.removeSwitchSkill(player, gongqi.name)
end)

return gongqi